{% extends 'Shared/layout.volt' %}
{% block title %}分组列表{% endblock %}
{% block content %}
    <section class="Hui-article-box">
        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i>
            <a href="/" title="首页">首页</a>
            <span class="c-gray en">&gt;</span>
            开放API
            <span class="c-gray en">&gt;</span>
            分组管理
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
        </nav>
        <div class="Hui-article">
            <article class="cl pd-20 w-980">

                <form action="{{ url('group/edit') }}" id="form-group-add" method="post" class="form form-horizontal" novalidate="novalidate">
                    <input type="hidden" name="groupCode" value="{{ Model.group_code }}" id="group-code">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分组名称：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text valid" value="{{ Model.group_name }}" placeholder="分组名称" id="group-name" name="groupName">
                            <span class="sub-text">分组名称必须唯一，支持汉字、英文字母、数字、英文格式的下划线，必须以英文字母或汉字开头，4~50个字符</span>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>流量控制(QPS)：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="number" class="input-text valid" value="{{ Model.traffic_value }}" placeholder="流量控制" id="traffic_value" name="trafficValue">
                            <span class="sub-text">分组下每个接口的流量控制，必须为数字，为 0 表示不限制</span>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分组状态：</label>
                        <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                            <div class="radio-box">
                                <input name="status" type="radio" id="status-enabled" {{ Model.status==0?'checked':'' }} value="0">
                                <label for="status-enabled">启用</label>
                            </div>
                            <div class="radio-box">
                                <input type="radio" id="status-disabled" name="status" {{ Model.status==1?'checked':'' }} value="1">
                                <label for="status-disabled">禁用</label>
                            </div>
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">分组备注：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <textarea name="description" cols="" rows="" class="textarea" placeholder="不超过200个字符" maxlength="200">{{ Model.description }}</textarea>
                        </div>
                    </div>
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                            <a href="{{ url('group/list') }}" title="返回列表" class="btn btn-default radius">&nbsp;&nbsp;返回&nbsp;&nbsp;</a>
                            <span style="display: inline-block;margin-left: 20px;font-size: 12px;" id="error-message"><?php $this->flashSession->output()?></span>
                        </div>
                    </div>
                </form>
            </article>
        </div>
    </section>

{% endblock %}
{% block scripts %}
    <script type="text/javascript">
        $(function () {
            $("#form-group-add").validate({
                rules:{
                    groupName:{
                        required:true,
                        validateGroupName:true
                    },
                    trafficValue : {
                        digits:true
                    },
                    description:{
                        maxlength:200,
                    }
                },
                messages :{
                    trafficValue :{
                        digits:'必须是正整数'
                    }
                },
                onkeyup:false,
                focusCleanup:true,
                success:"valid",
                submitHandler:function(form){
                    $(form).ajaxSubmit({
                        success : function ($response) {
                            if($response.error_code === 0){
                                $("#group-code").val($response.data.group_code);
                                $("#error-message").showSuccess($response.message);
                            }else{
                                $("#error-message").showError($response.message);
                            }
                        }
                    });
                }
            });

        });
    </script>
{% endblock %}